


function findvideo() {
    var values = document.getElementById("selectone").value;
    var valuess = document.getElementById("selecttwo").value;
    var back=document.getElementsByClassName("groups__item");

    console.log(back);
    /* $.ajax({
         type:"post",
         url:ctx+"test/select",
         dataType:"json",
         data:{

         },
         success:function (s) {
             alert(s);
             alert("dsadasf");


         }
     });*/

    $.ajax({
        type: "post",
        url: ctx + "video/select",
        dataType: "json",
        data: {
            type: values,

        },
        success: function (r) {


            if (r.total > 0) {
                console.log(valuess);
                if (valuess == "视频") {


                    var movie_list = r.rows;
                    var movie_list_html = "";
                    /*var img = '61.181.104.62:8081/Projectpicture/websiteimages/finshvideo/1548811263803.mp4'*/

                    for (var i = 0; i < r.rows.length; i++) {
                        var img = r.rows[i].videoUrl;
                        console.log("视频路径信息")
                        console.log(img);


                        movie_list_html += '<div class="col-xl-3 col-lg-3 col-sm-4 col-6">';

                        movie_list_html += '<div class="groups__item">';
                        movie_list_html += '<li class="movie-img aspectration" data-ratio="16:9" style="background-image:url(' + movie_list[i].photoUrl + ');"></li>';
                        //视频标签
                        movie_list_html += '<div class="groups__info">';
                        movie_list_html += '<strong>' + movie_list[i].title + '</strong>';
                        movie_list_html += '<small>' + movie_list[i].describle + '</small>';

                        // movie_list_html += getScoreHtml(movie_list[i].r);
                        movie_list_html += '</div>';


                        movie_list_html += '<div class="dropdown-menu dropdown-menu-right movie-action" style="min-width:100px;background-color:rgba(255,255,255,.9);z-index:1">';
                        // movie_list_html += '<a class="dropdown-item" onclick="getMoiveDetail(\'' + movie_list[i].id + '\');" href="javascript:void(0)">查看详情</a>';
                        movie_list_html += '<a class="dropdown-item" onclick="getMoiveComments(\'' + sendprisonerNo + '\',\'' + movie_list[i].videoUrl + '\',\'' + movie_list[i].photoUrl + '\');" href="javascript:void(0)">学习视频</a>';
                        movie_list_html += '</div></div></div>';
                    }
                    $(".movie-list").html("").append(movie_list_html);
                    $(".groups__item").each(function () {
                        var $this = $(this);
                        $this.mouseenter(function () {
                            $this.find(".movie-action").show();
                        });
                        $this.mouseleave(function () {
                            $this.find(".movie-action").hide();
                        });
                    });
                }
                if (valuess == "文本") {
                    console.log("进入文本");

                    for (var i = 0; i < r.rows.length; i++) {
                        var texturl = r.rows[i].textUrl;
                        console.log(texturl);


                        var movie_list = r.rows;
                        var movie_list_html = "";
                        /*var img = '61.181.104.62:8081/Projectpicture/websiteimages/finshvideo/1548811263803.mp4'*/

                        for (var i = 0; i < r.rows.length; i++) {

                          movie_list_html += '<div class="col-xl-3 col-lg-3 col-sm-4 col-6">';

                            movie_list_html += '<div class="groups__item">';
                            movie_list_html += '<li class="movie-img aspectration" data-ratio="16:9" style="background-image:url(' + movie_list[i].photoUrl + ');"></li>';
                            //视频标签
                            movie_list_html += '<div class="groups__info">';
                            movie_list_html += '<strong>' + movie_list[i].title + '</strong>';
                            movie_list_html += '<small>' + movie_list[i].describle + '</small>';

                            // movie_list_html += getScoreHtml(movie_list[i].r);
                            movie_list_html += '</div>';


                            movie_list_html += '<div class="dropdown-menu dropdown-menu-right movie-action" style="min-width:100px;background-color:rgba(255,255,255,.9);z-index:1">';
                            // movie_list_html += '<a class="dropdown-item" onclick="getMoiveDetail(\'' + movie_list[i].id + '\');" href="javascript:void(0)">查看详情</a>';
                            movie_list_html += '<a class="dropdown-item" onclick="getTextContext(\'' + texturl + '\');" href="javascript:void(0)">学习文本</a>';
                            movie_list_html += '</div></div></div>';
                        }
                        $(".movie-list").html("").append(movie_list_html);
                        $(".groups__item").each(function () {
                            var $this = $(this);
                            $this.mouseenter(function () {
                                $this.find(".movie-action").show();
                            });
                            $this.mouseleave(function () {
                                $this.find(".movie-action").hide();
                            });
                        });

                    }
                    console.log("离开循环")
                    /* $(".movie-list").html("").append("<img src='http://61.181.104.62:8081\\Projectpicture\\websiteimages\\finshimg\\1000.jpg'>")*/
                    console.log("---------")
                }
            } else {
                $MB.n_danger(r.msg);
            }


        }

    });


}

function funcvideoList(sendprisonerNo, sendname, stelephone, sminnute) {
    alert(sendname + '这个月看了' + sminnute + '分钟的视频');
     console.log("11");

    $.post(ctx + 'video/select', {}, function (r) {
        if (r != '') {

            /*alert(r.rows.length);*/
            // var data = JSON.parse(r.msg);
            /*console.log(r.rows);*/
            var movie_list = r.rows;
            var movie_list_html = "";
            var study_select = "";
            /* var img = '61.181.104.62:8081/Projectpicture/websiteimages/finshvideo/1548811263803.mp4'*/
            var photourl = '61.181.104.62:8081/Projectpicture/websiteimages/finshimg/1000.jpg';
            study_select += '<div>';
            study_select += '<strong >' + sendname + "本月观看了" + sminnute + "分钟视频" + '</strong>';
            study_select += '</div>';
            study_select += '<div >';
            study_select += '<strong >视频种类:</strong>';
            study_select += '<select id="selectone" value="视频种类">'

            study_select += '  <option  value="法治">法治</option>\n'
            study_select += '  <option  value="法律类">法律类</option>\n'
            study_select += '  <option  value="新闻">新闻</option>\n'
            study_select += '  <option  value="事实">事实</option>\n'
            study_select += '</select>';
            study_select += '<strong >视频类型:</strong>';
            study_select += '<select id="selecttwo"  value="视频类型">'
            study_select += '  <option  value="文本">文本</option>\n'
            study_select += '  <option  value="视频">视频</option>\n'
            study_select += '</select>';
            study_select += '<input type="button" id="button_find" value="搜索" \n' +
                'onclick="findvideo()">';
            study_select += '</div>';
            for (var i = 0; i < r.rows.length; i++) {

                /*alert(movie_list[i].photoUrl);*/
                var videourl = r.rows[i].videoUrl;
                var texturl=r.rows[i].textUrl;
                if(videourl !=null && videourl !="") {
                    console.log("所有的视频路径信息")
                    console.log(videourl);
                    console.log(r.rows[i].textUrl);


                    movie_list_html += '<div class="col-xl-3 col-lg-3 col-sm-4 col-6">';

                    movie_list_html += '<div class="groups__item">';
                    movie_list_html += '<li class="movie-img aspectration" data-ratio="16:9" style="background-image:url(' + movie_list[i].photoUrl + ');"></li>';
                    console.log(movie_list[i].photoUrl);
                    //视频标签
                    movie_list_html += '<div class="groups__info">';
                    movie_list_html += '<strong>' + movie_list[i].title + '</strong>';
                    movie_list_html += '<small>' + movie_list[i].describle + '</small>';

                    // movie_list_html += getScoreHtml(movie_list[i].r);
                    movie_list_html += '</div>';


                    movie_list_html += '<div class="dropdown-menu dropdown-menu-right movie-action" style="min-width:100px;background-color:rgba(255,255,255,.9);z-index:1">';
                    // movie_list_html += '<a class="dropdown-item" onclick="getMoiveDetail(\'' + movie_list[i].id + '\');" href="javascript:void(0)">查看详情</a>';

                    movie_list_html += '<a class="dropdown-item" onclick="getMoiveComments(\'' + sendprisonerNo + '\',\'' + movie_list[i].videoUrl + '\',\'' + movie_list[i].photoUrl + '\');" href="javascript:void(0)">学习视频</a>';
                    movie_list_html += '</div></div></div>';
                }
                else{
                    movie_list_html += '<div class="col-xl-3 col-lg-3 col-sm-4 col-6">';

                    movie_list_html += '<div class="groups__item">';
                    movie_list_html += '<li class="movie-img aspectration" data-ratio="16:9" style="background-image:url(' + movie_list[i].photoUrl + ');"></li>';
                    //视频标签
                    movie_list_html += '<div class="groups__info">';
                    movie_list_html += '<strong>' + movie_list[i].title + '</strong>';
                    movie_list_html += '<small>' + movie_list[i].describle + '</small>';

                    // movie_list_html += getScoreHtml(movie_list[i].r);
                    movie_list_html += '</div>';


                    movie_list_html += '<div class="dropdown-menu dropdown-menu-right movie-action" style="min-width:100px;background-color:rgba(255,255,255,.9);z-index:1">';
                    // movie_list_html += '<a class="dropdown-item" onclick="getMoiveDetail(\'' + movie_list[i].id + '\');" href="javascript:void(0)">查看详情</a>';
                    movie_list_html += '<a class="dropdown-item" onclick="getTextContext(\'' + texturl + '\');" href="javascript:void(0)">学习文本</a>';
                    movie_list_html += '</div></div></div>';

                }
            }


            $(".study-select").html("").append(study_select);
            $(".movie-list").html("").append(movie_list_html);
            $(".groups__item").each(function () {
                var $this = $(this);
                $this.mouseenter(function () {
                    $this.find(".movie-action").show();
                });
                $this.mouseleave(function () {
                    $this.find(".movie-action").hide();
                });
            });
        } else {
            $MB.n_danger(r.msg);
        }
    });
}

function getScoreHtml(score) {
    var html = '';
    if (score >= 9) {
        html = '<div class="widget-ratings__star">' +
            '<i class="zmdi zmdi-star active"></i>' +
            '<i class="zmdi zmdi-star active"></i>' +
            '<i class="zmdi zmdi-star active"></i>' +
            '<i class="zmdi zmdi-star active"></i>' +
            '<i class="zmdi zmdi-star active"></i>&nbsp;' + score + '</div>';
    } else if (score >= 8) {
        html = '<div class="widget-ratings__star">' +
            '<i class="zmdi zmdi-star active"></i>' +
            '<i class="zmdi zmdi-star active"></i>' +
            '<i class="zmdi zmdi-star active"></i>' +
            '<i class="zmdi zmdi-star active"></i>' +
            '<i class="zmdi zmdi-star"></i>&nbsp;' + score + '</div>';
    } else if (score >= 6) {
        html = '<div class="widget-ratings__star">' +
            '<i class="zmdi zmdi-star active"></i>' +
            '<i class="zmdi zmdi-star active"></i>' +
            '<i class="zmdi zmdi-star active"></i>' +
            '<i class="zmdi zmdi-star"></i>' +
            '<i class="zmdi zmdi-star"></i>&nbsp;' + score + '</div>';
    } else if (score >= 4) {
        html = '<div class="widget-ratings__star">' +
            '<i class="zmdi zmdi-star active"></i>' +
            '<i class="zmdi zmdi-star active"></i>' +
            '<i class="zmdi zmdi-star"></i>' +
            '<i class="zmdi zmdi-star"></i>' +
            '<i class="zmdi zmdi-star"></i>&nbsp;' + score + '</div>';
    } else if (score >= 2) {
        html = '<div class="widget-ratings__star">' +
            '<i class="zmdi zmdi-star active"></i>' +
            '<i class="zmdi zmdi-star"></i>' +
            '<i class="zmdi zmdi-star"></i>' +
            '<i class="zmdi zmdi-star"></i>' +
            '<i class="zmdi zmdi-star"></i>&nbsp;' + score + '</div>';
    } else {
        html = '<div class="widget-ratings__star">' +
            '<i class="zmdi zmdi-star"></i>' +
            '<i class="zmdi zmdi-star"></i>' +
            '<i class="zmdi zmdi-star"></i>' +
            '<i class="zmdi zmdi-star"></i>' +
            '<i class="zmdi zmdi-star"></i>&nbsp;<span style="font-size:1rem">暂无评分</span></div>';
    }
    return html;
}

function getMoiveDetail(id) {
    $.post(ctx + "movie/detail", {"id": id}, function (r) {
        if (r.code === 0) {
            var data = JSON.parse(r.msg).data;
            var basic = data.basic;
            $("#img").attr("src", basic.img);
            var movieName = basic.name;
            if (basic.nameEn) {
                movieName += " / " + basic.nameEn;
            }
            $("#name").text("片名：" + movieName);
            $("#director").text("导演：" + basic.director.name);
            var curr = basic.releaseDate;
            var dateStr = curr.substr(0, 4) + "-" + curr.substr(4, 2) + "-" + curr.substr(6, 2);
            $("#releaseDate").text("上映日期：" + dateStr);
            $("#releaseArea").text("上映地区 / 国家：" + basic.releaseArea);
            $("#mins").text("片长：" + basic.mins);
            $("#is3D").text("是否3D：" + (basic.is3D ? "是" : "否"));
            $("#isIMAX").text("是否IMAX：" + (basic.isIMAX ? "是" : "否"));
            $("#movie-story").text(basic.story);
            var actors = basic.actors;
            var actors_html = "主演：";
            for (var i = 0; i < actors.length; i++) {
                if (!actors[i].name) continue;
                if (i === 0)
                    actors_html += '<a href="' + actors[i].img + '" target="_blank">' + actors[i].name + '</a>';
                else
                    actors_html += ' / <a href="' + actors[i].img + '" target="_blank">' + actors[i].name + '</a>';
            }
            $("#actors_list").html(actors_html);
            var video_html = '<a href="' + basic.video.hightUrl.replace("https", "http") + '" target="_blank">点击查看</a>';
            $("#previw span").html(video_html);
            var $form = $('#movie-detail');
            $form.modal();
        } else {
            $MB.n_danger(r.msg);
        }
    });
}
function getTextContext(texturl) {
    console.log("点击事件生效");
    console.log(texturl);
    $.ajax({
        type: "post",
        url: ctx + "text/read",
        dataType: "json",
        data: {
            textUrl: texturl,

        },
        success: function (r) {
            console.log("执行text/read方法")
            var strs=r.msg;
            console.log(strs);
            var text_comments_html = "";
            var text_content=""
            text_content+='<div>';
            text_content+='<pre>' + strs + '</pre>';
            text_content+='</div>';
         text_comments_html += " <div class='m' style='  height: 600px; '></div><input type='text' style='display: none' id='aa' value='0'>";

            $("#listview--bordered").html("").append(text_content);
            var $form = $('#movie-comments');
            $form.modal();
        }
    })
}

function getMoiveComments(id, url, photoUrl) {

    var comments_html = "";
    comments_html += "  <div class='m' style='  height: 600px; '><video id='my-video' class='video-js' controls preload='auto' width='650' height='590' poster='" + photoUrl + "' data-setup='{}'><source src='" + url + "' type='video/mp4'></video> </div><input type='text' style='display: none' id='aa' value='0'> ";
    $("#listview--bordered").html("").append(comments_html);
    var $form = $('#movie-comments');
    $form.modal();
    videosart(id)
    // $.post(ctx + "movie/comments", {"id": id}, function (r) {
    //     var data = JSON.parse(r.msg).data;
    //     var mini = data.mini.list;
    //     var plus = data.plus.list;
    //     if (!mini.length && !plus.length) {
    //         $MB.n_warning("该影片暂无评论");
    //         return;
    //     }
    //     $("#movie-comments-modal-title").text("《" + title + "》影评");
    //     var comments_html = "";
    //     for (var i = 0; i < mini.length; i++) {
    //         comments_html += '<div class="listview__item">';
    //         comments_html += '<label class="custom-control custom-control--char todo__item">';
    //         comments_html += '<span class="custom-control-char"><img src="' + mini[i].headImg + '"/></span>';
    //         comments_html += '<div class="todo__info">';
    //         comments_html += '<span style="display:inline-block">' + mini[i].nickname + '</span>&nbsp;&nbsp;';
    //         comments_html += '<small style="display:inline-block">' + getDate(mini[i].commentDate) + '</small>';
    //         comments_html += '</div><div class="comments__info" style="padding: 6px 0">';
    //         comments_html += '<span>' + mini[i].content + '</span></div></label></div>';
    //     }
    //     for (var i = 0; i < plus.length; i++) {
    //         comments_html += '<div class="listview__item">';
    //         comments_html += '<label class="custom-control custom-control--char todo__item">';
    //         comments_html += '<span class="custom-control-char"><img src="' + plus[i].headImg + '"/></span>';
    //         comments_html += '<div class="todo__info">';
    //         comments_html += '<span style="display:inline-block">' + plus[i].nickname + '</span>&nbsp;&nbsp;';
    //         comments_html += '<small style="display:inline-block">' + getDate(plus[i].commentDate) + '</small>';
    //         comments_html += '</div><div class="comments__info" style="padding: 6px 0">';
    //         comments_html += '<span>' + plus[i].content + '</span></div></label></div>';
    //     }
    //     $(".listview--bordered").html("").append(comments_html);
    //     var $form = $('#movie-comments');
    //     $form.modal();
    // });
}

function getDate(tm) {
    return new Date(tm * 1000).toLocaleString();
}